/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

   

    var map;
    var gdir;
    var geocoder ;
    var address;

   /* function initialize() {
      if (GBrowserIsCompatible()) {
        map = new GMap2(document.getElementById("map"));                 //Initialise une carte google Map dans le div map_canevas
        gdir = new GDirections(map, document.getElementById("direction"));     //Initialise le div direction pour afficher la direction à prendre
        GEvent.addListener(gdir, "load", onGDirectionsLoad);
        GEvent.addListener(gdir, "error", handleErrors);

        //setDirections("Paris", "Franconville", "fr");
      }
    }

    function setDirections(fromAddress, toAddress, locale) {
      gdir.load("from: " + fromAddress + " to: " + toAddress,                   //Initialise un itinéraire
                { "locale": locale });
    }*/


    function initialize() {
      map = new GMap2(document.getElementById("carte"));
      map.setCenter(new GLatLng(10, 0), 2);
      map.addControl(new GLargeMapControl);
      GEvent.addListener(map, "click", getAddress);
      geocoder = new GClientGeocoder();
    }

    function getAddress(overlay, latlng) {
      if (latlng != null) {
        address = latlng;
        geocoder.getLocations(latlng, showAddress);
      }
    }

    function showAddress(response) {
      map.clearOverlays();
      if (!response || response.Status.code != 200) {
        alert("L'adresse ne peut pas être trouvée");
      }
      else {
        place = response.Placemark[0];
        point = new GLatLng(place.Point.coordinates[1],
                            place.Point.coordinates[0]);
        marker = new GMarker(point);
        map.addOverlay(marker);
        marker.openInfoWindowHtml('<form method="POST" action="#"><table>' +
                         '<tr><td><img src="images/flag.gif">&nbsp;Départ:</td> <td><input type="text" size="30" name="adr" id="adr" value="' + place.address + '"></td> </tr>' +
                         '<tr><td>Latitude:</td> <td><input readonly type="text" size="10" name="lat" id="lat" value="' + place.Point.coordinates[1] + '"></td> </tr>' +
                         '<tr><td>Longitude:</td> <td><input readonly type="text" size="10" name="lng" id="lng" value="' + place.Point.coordinates[0] + '"></td> </tr>' +
                         '<tr><td>En voiture <img src="images/drive.gif"><input type="radio" name="moyen" value="car"></td> ' +
                         '<td>A pied <img src="images/walk.gif"><input type="radio" name="moyen" value="walk"></td></tr>' +
                         '<tr><td></td><td><input type="submit" value="Trouver Commerce"></td></tr>' +
                   '</table></form>');
      }
    }

    function montrerAdresse(rue,ville,pays) {
        
     var parametre =rue+", "+ville+", "+pays;
  
     if (geocoder) {
        geocoder.getLocations(parametre,showAddress);
      }
        
    }
